package dto

import (
	"fmt"
	"time"
	"vrcm/src/vrcm/app/admin/models/subject"
	"vrcm/src/vrcm/common/dto"
	common "vrcm/src/vrcm/common/models"
)

type PaperGetPageReq struct {
	dto.Pagination `search:"-"`
	IsDelete       int `json:"is_delete" search:"type:exact;column:is_delete;table:paper"`
	PaperType      int `json:"paper_type" search:"type:exact;column:paper_type;table:paper"`
	//PaperOrder
}

type PaperOrder struct {
	Id         string `form:"idOrder"  search:"type:order;column:id;table:paper"`
	PaperName  string `form:"paper_nameOrder"  search:"type:order;column:paper_name;table:paper"`
	PaperDesc  string `form:"paper_descOrder"  search:"type:order;column:paper_desc;table:paper"`
	ShowAnswer string `form:"show_answerOrder"  search:"type:order;column:show_answer;table:paper"`
	IsDelete   string `form:"is_deleteOrder"  search:"type:order;column:is_delete;table:paper"`
	CreateTime string `form:"create_timeOrder"  search:"type:order;column:create_time;table:paper"`
	UpdateTime string `form:"update_timeOrder"  search:"type:order;column:update_time;table:paper"`
	CreateBy   string `form:"createByOrder"  search:"type:order;column:create_by;table:paper"`
	UpdateBy   string `form:"updateByOrder"  search:"type:order;column:update_by;table:paper"`
}

func (m *PaperGetPageReq) GetNeedSearch() interface{} {
	fmt.Println(m)
	return *m
}

type PaperInsertReq struct {
	Id         int    `json:"-" comment:""` //
	PaperName  string `json:"paper_name" comment:"试卷名称" validate:"required,max=50"`
	PaperDesc  string `json:"paper_desc" comment:"试卷描述" validate:"required,max=200"`
	ShowAnswer int    `json:"show_answer" comment:"答案显示 1.结束后显示答案 2答题后显示答案 3不显示答案" validate:"required,max=100,gt=0,lte=3"`
	common.ControlBy
}

func (s *PaperInsertReq) Generate(model *subject.Paper) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.PaperName = s.PaperName
	model.PaperDesc = s.PaperDesc
	model.ShowAnswer = s.ShowAnswer
	model.IsDelete = 2
	model.CreateTime = time.Now().Unix()
	model.UpdateTime = time.Now().Unix()
	model.CreateBy = s.CreateBy // 添加这而，需要记录是被谁创建的
	model.PaperType = 2
}

func (s *PaperInsertReq) GetId() interface{} {
	return s.Id
}

type PaperUpdateReq struct {
	Id         int    `uri:"id" comment:"" validate:"required"` //
	PaperName  string `json:"paper_name" comment:"试卷名称" validate:"required,max=50"`
	PaperDesc  string `json:"paper_desc" comment:"试卷描述" validate:"required,max=200"`
	ShowAnswer int    `json:"show_answer" comment:"答案显示 1.结束后显示答案 2答题后显示答案 3不显示答案" validate:"required,gt=0,lte=3"`
	common.ControlBy
}

func (s *PaperUpdateReq) Generate(model *subject.Paper) {
	if s.Id == 0 {
		model.Model = common.Model{Id: s.Id}
	}
	model.PaperName = s.PaperName
	model.PaperDesc = s.PaperDesc
	model.ShowAnswer = s.ShowAnswer
	model.UpdateTime = time.Now().Unix()
	model.UpdateBy = s.UpdateBy // 添加这而，需要记录是被谁更新的
}

func (s *PaperUpdateReq) GetId() interface{} {
	return s.Id
}

// PaperGetReq 功能获取请求参数
type PaperGetReq struct {
	Id int `uri:"id"`
}

func (s *PaperGetReq) GetId() interface{} {
	return s.Id
}

// PaperDeleteReq 功能删除请求参数
type PaperDeleteReq struct {
	Ids []int `json:"ids"  validate:"required"`
}

func (s *PaperDeleteReq) GetId() interface{} {
	return s.Ids
}
